package everydayGrade.t3;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Siantar
 * @Date: 2023-12-05-15:39
 * @Description: 1.0
 */
public class T2477 {
    long res = 0;

    public long minimumFuelCost(int[][] roads, int seats) {
        List<Integer>[] mp = creatTable(roads, roads.length + 1);
        bfs(mp, 0, -1, seats);
        return res;
    }

    public long bfs(List<Integer>[] mp, int p, int pre, int seats) {
        long cnt = 1;
        for (int next : mp[p]) {
            if (next == pre) continue;
            long nextCnt = bfs(mp, next, p, seats);
            cnt += nextCnt;
            res += (nextCnt - 1) % seats + 1;
            System.out.println(next + " " + nextCnt + " " + (nextCnt - 1) % seats + 1);
        }
        return cnt;
    }

    public List<Integer>[] creatTable(int[][] edges, int n) {
        List<Integer>[] mp = new List[n];
        for (int i = 0; i < n; ++i) {
            mp[i] = new ArrayList<Integer>();
        }
        for (int[] e : edges) {
            int from = e[0], to = e[1];
            mp[from].add(to);
            mp[to].add(from);
        }
        return mp;
    }
}
